package com.etooling.framework.repository;


import com.etooling.framework.entity.Tag;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TagRepository extends BaseRepository<Tag> {
    @Query(nativeQuery = true, value = "select * from framework.t_tag tag where  shear_type=?2 and case when ?2='个人' then create_user_id=?4 else 1=1 end  and  target in (?1) and company_id=?3 order by  id")
    List<Tag> getChildren(List target, String shearType, String companyId, String loginUserId);


    @Query(nativeQuery = true, value = "select * from framework.t_tag where id in(?1) ")
    List<Tag> getListByIds(List<String> tagsId);


    @Query(nativeQuery = true, value = "select * from framework.t_tag where company_id=?2 and name =?1  limit 1")
    Tag getOneByName(String tagName, String companyId);

    @Query(nativeQuery = true, value = "select name FROM framework.t_tag where  target = ?2 and name in (?1) and company_id = ?3  ")
    List<String> getInTag(List<String> tagList, String type, String companyId);

    @Query(nativeQuery = true, value = "select * from framework.t_tag tag where id in (select tag_id from wms.t_material_tag where material_id in (select material_id from purchase.t_pr_order_detail where pr_order_id = ?1 )  )  ")
    List<Tag> getChildrenByPrOrder(String prOrderId);
}
